package com.pengheng.controller;

import cn.hutool.core.util.HexUtil;
import com.pengheng.mqtt.platform.MqttPushClient;
import com.pengheng.mqtt.uav.UAVMqttPushClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/")
public class SendController {

    @Resource
    private MqttPushClient mqttPushClient;

    @Resource
    private UAVMqttPushClient uavMqttPushClient;

    @RequestMapping("/testMqtt")
    public String sendMqtt(@RequestParam(value = "topic") String topic, @RequestParam(value = "message") String message) {
        mqttPushClient.publish(topic, message);
        return "SUCCESS";
    }

    @RequestMapping("/testUAVMqtt")
    public String sendUAVMqtt(@RequestParam(value = "topic") String topic, @RequestParam(value = "message") String message) {
        uavMqttPushClient.publish(topic, message);
        return "SUCCESS";
    }


    @RequestMapping("/wpset")
    public String ctrlUSV(String message) {
//        String hexStr = "000003003F0C7123DC9A661F3ECA2A3DC8000000003F0BBD23DC9C4E65BF0E2E5C2380000000BEF1FFB846D6EE59BF0EB55C23800000";
        byte[] bytes = HexUtil.decodeHex(message);
        mqttPushClient.publish("/wp/set", bytes);
        //开始执行任务
        mqttPushClient.publish("/nav/start", "");
        //停止执行任务
        mqttPushClient.publish("/nav/stop", "");
        return "SUCCESS";
    }

    public static void main(String[] args) {
        String str = "";
        System.out.println(str.getBytes().length);
    }

}
